/*
 * @version: 
 * @Author: yu
 * @Date: 2023-07-10 15:51:00
 * @LastEditors: Andy
 * @LastEditTime: 2023-07-13 14:25:05
 */
import { createStore } from 'vuex'

import menu from './modules/menu'
import role from './modules/role'
import member from './modules/member'
import cate from './modules/cate'
export default createStore({
  state: {
    user: sessionStorage.getItem('user') ? JSON.parse(sessionStorage.getItem('user') as any) : null
  },
  getters: {
    user(state) {
      return state.user
    }
  },
  mutations: {
    changeUser(state, user) {
      if (user) {
        //修改状态管理
        state.user = user
        //数据缓存
        sessionStorage.setItem('user', JSON.stringify(user))
      } else {
        sessionStorage.removeItem('user')
      }
    }
  },
  actions: {
    userActions(context, user) {
      context.commit('changeUser', user)
    }
  },
  modules: {
    menu,
    role,
    member,
    cate
  }
})
